<template>
    <div>
      <a-drawer
      width="1100"
      :maskClosable="false"
      :visible="dialogData.show"
      direction="rtl"
      @close="handleClose">
        <div slot="title">
          <!-- <i class="el-icon-arrow-left"></i> -->
          <i style="cursor: pointer" v-if="dialogData.origin == 'ec'" class="el-icon-arrow-left" @click="handleBack"></i>
          <span>{{dialogData.title}}</span>
        </div>
        <el-row style="width:1120px;padding-bottom:150px;height:100%;overflow-y:auto">
          <el-col :span="18">
             <el-form v-loading="loading" :model="parames" :rules="rules" label-position="left" ref="parames" label-width="94px" class="addForm">
                <el-row style="padding: 0 40px" >
                  <a-collapse :defaultActiveKey="activeNames" :bordered="false">
                    <a-collapse-panel class="marginB10" header="基本信息" key="1">
                      <el-col :span="12" style="margin-top: 14px">
                          <el-form-item label="联系人:" prop="contacts">
                            <el-input size="small" v-model="parames.contacts" placeholder="请输入联系人姓名"></el-input>
                          </el-form-item>
                          <el-form-item label="联系方式:" prop="mobile">
                            <el-row >
                              <el-col :span="8">
                                <el-select size="small" v-model="parames.contactType" placeholder="请选择">
                                  <el-option v-for="(item,index) in contactType" :key="index" :label="item.desc" :value="item.name"></el-option>
                                </el-select>
                              </el-col>
                              <el-col :span="16">
                                <el-input size="small" v-model="parames.mobile" placeholder="请输入"></el-input>
                              </el-col>
                            </el-row>
                          </el-form-item>
                          
                          <el-form-item label="商机来源:" prop="opportunitySourceId">
                            <shangJi v-model="parames.opportunitySourceId" @checkValue="checkValue" :typeid="parames.opportunitySourceType" :id="parames.opportunitySourceId" :type="dialogData.type"></shangJi>
                          </el-form-item>
                      </el-col>
                      <el-col :span="24">
                        <el-form-item label="公司名称:" prop="customerId" class="is-required">
                          <el-select v-show="showKehu" style="width:285px;" size="small" filterable v-model="parames.customerId" placeholder="请选择">
                            <el-option v-for="(item,index) in kehuData" :key="index" :label="item.customerName" :value="item.id"></el-option>
                          </el-select>
                          <el-input v-show="!showKehu" size="small" style="width:285px;" v-model="parames.customerName" placeholder="请输入客户名称"></el-input>
                          <!-- <el-button class="button-new-tag" size="small" @click="handleSelectCustomer">
                            <span v-show="showKehu">+ 创建新客户</span>
                            <span v-show="!showKehu">选择客户</span>
                          </el-button> -->
                        </el-form-item>
                        <el-form-item label="添加标签:">
                          <el-row>
                            <el-col :span="4">
                              <el-select size="small" v-model="parames.urgencyLabel"  placeholder="请选择优先级">
                                  <el-option v-for="(item,index) in urgencyData" :key="index" :label="item.desc" :value="item.name"></el-option>
                              </el-select>
                            </el-col>
                            <el-col :span="8">
                              <el-select size="small" v-model="parames.importanceLabel" placeholder="请选择客户喜好">
                                  <el-option v-for="(item,index) in importData" :key="index" :label="item.desc" :value="item.name"></el-option>
                                </el-select>
                            </el-col>
                            <el-col :span="12">
                              <el-tag
                                :key="tag"
                                v-for="tag in parames.customLabelList"
                                closable
                                :disable-transitions="false"
                                @close="handleCloseTag(tag)">
                                {{tag}}
                              </el-tag>
                              <el-input
                                style="width: 100px"
                                v-if="inputVisible"
                                v-model="inputValue"
                                ref="saveTagInput"
                                size="small"
                                @keyup.enter.native="handleInputConfirm"
                                @blur="handleInputConfirm"
                              >
                              </el-input>
                              <el-button v-else class="button-new-tag" size="small" @click="showInput">+ 添加标签</el-button>
                            </el-col>
                          </el-row>
                        </el-form-item>
                      </el-col>
                      <el-col :span="16">
                        <el-form-item label="推荐方案:">
                          <el-button size="small" @click="handleOpenCase" v-if="!parames.thinkTankId">开始创建</el-button>
                          <el-button size="small" @click="handleViewCase" v-if="parames.thinkTankId">查看方案</el-button>
                        </el-form-item>
                          <!-- <el-form-item label="负责人:" prop="director">
                            <userTree v-model="parames.responsiblePerson" :currentValue="parames.responsiblePerson"></userTree>
                          </el-form-item> -->
                        <el-form-item label="需求概述:">
                          <el-input size="small" type="textarea" v-model="parames.opportunityOverview" placeholder="请输入需求概述"></el-input>
                        </el-form-item>
                      </el-col>
                    </a-collapse-panel>
                    <a-collapse-panel class="marginB10" header="推荐产品" key="2">
                      <el-col :span="24">
                        <el-form-item label="快速添加:" prop="name" >
                          <el-tag style="margin-right:5px;cursor:pointer" :class="item.isSelect?'tab-cur':''" v-for="(item,index) in groupListta" @click.native="handleTags(item,index)" :key="index" :type="item.isSelect?'':'info'" effect="plain" size="medium">{{item.groupName}}</el-tag>
                        </el-form-item>
                        <el-table
                          class="line-form"
                          :data="parames.opportunityProductList"
                          show-summary
                          :summary-method="getSummaries"
                          style="width: 100%">
                          <el-table-column
                            type="index"
                            label="序号"
                            width="50">
                          </el-table-column>
                          <el-table-column
                            prop="productName"
                            label="产品名称"
                            width="100">
                          </el-table-column>
                          <el-table-column label="产品价格" width="110">
                              <template slot-scope="scope">
                                  <span>{{scope.row.lowerPriceLimit}}-{{scope.row.upperPriceLimit}}</span>
                              </template>
                          </el-table-column>
                          <el-table-column
                            width="80"
                            prop="count"
                            label="数量">
                            <template slot-scope="scope">
                              <el-form-item
                                style="margin-bottom: 0"
                                :prop="'opportunityProductList.' + scope.$index + '.count'"
                                label-width="0"
                                :rules="[
                                  { required: true, message: '不能为空', trigger: ['blur', 'change'] },
                                  { type: 'number', message: '请输入正整数', trigger: ['blur', 'change'] }
                                ]"
                              >
                                <span v-if="scope.row.productServiceType">
                                  <el-input :disabled="scope.row.productServiceType.name == 'DISPOSABLE'" v-model.number="scope.row.count" size="small"></el-input>
                                </span>
                              </el-form-item>
                            </template>
                          </el-table-column>
                          <el-table-column
                            prop="giftCount"
                            label="赠送数量">
                            <template slot-scope="scope">
                              <el-form-item
                                style="margin-bottom: 0"
                                :prop="'opportunityProductList.' + scope.$index + '.giftCount'"
                                label-width="0"
                                :rules="[
                                  { required: true, message: '不能为空', trigger: ['blur', 'change'] },
                                  { type: 'number', message: '请输入正整数', trigger: ['blur', 'change'] }
                                ]"
                              >
                              <span v-if="scope.row.productServiceType">
                                <el-input :disabled="scope.row.productServiceType.name == 'DISPOSABLE'" v-model.number="scope.row.giftCount" size="small"></el-input>
                              </span>
                              </el-form-item>
                            </template>
                          </el-table-column>
                          <el-table-column
                            prop="unitPrice"
                            width="90"
                            label="单价(元)">
                            <template slot-scope="scope">
                              <el-form-item
                                style="margin-bottom: 0"
                                :prop="'opportunityProductList.' + scope.$index + '.unitPrice'"
                                label-width="0"
                                :rules="[
                                  { required: true, message: '不能为空', trigger: ['blur', 'change'] },
                                  { type: 'number', message: '请输入正整数', trigger: ['blur', 'change'] }
                                ]"
                              >
                                <el-input v-model.number="scope.row.unitPrice" size="small"></el-input>
                              </el-form-item>
                            </template>
                          </el-table-column>
                          <el-table-column
                            prop="discount"
                            width="90"
                            label="优惠(元)">
                            <template slot-scope="scope">
                              <el-form-item
                                style="margin-bottom: 0"
                                :prop="'opportunityProductList.' + scope.$index + '.discount'"
                                label-width="0"
                                :rules="[
                                  { required: true, message: '不能为空', trigger: ['blur', 'change'] },
                                  { type: 'number', message: '请输入正整数', trigger: ['blur', 'change'] },
                                ]"
                              >
                                <el-input v-model.number="scope.row.discount" size="small"></el-input>
                              </el-form-item>
                            </template>
                          </el-table-column>
                          <el-table-column label="小计">
                              <template slot-scope="scope">
                                  <span>{{scope.row.count*scope.row.unitPrice-scope.row.discount}}</span>
                              </template>
                          </el-table-column>
                          <el-table-column
                            prop="address"
                            width="60"
                            label="操作">
                            <template slot-scope="scope">
                              <el-button size="mini" type="text" icon="el-icon-delete" @click.native="handleDelproduct(scope.$index,scope.row)"></el-button>
                            </template>
                          </el-table-column>
                        </el-table>
                        <el-button icon="el-icon-plus" size="small" @click="handelAddProduct" style="width:100%;margin-top:20px">添加产品</el-button>
                      </el-col>
                    </a-collapse-panel>
                  </a-collapse>
                </el-row>
              </el-form>
            </el-col>
          
          <el-col :span="5" style="position: fixed;top:80px;right:-10px;width:240px">
            <div v-if="dialogData.type == 'edit'">
              <el-button
                @click="handleCancle"
                size="small"
                icon="el-icon-close"
                style="width:200px;text-align: left;margin-bottom:10px"
              >取消编辑</el-button>
            </div>
            <div class="form-team-box">
              <p class="formtitle" v-if="parames.userIdList">团队成员（{{parames.userIdList.length}}）人</p>
              <el-row style="margin-top:10px">
                <span v-for="(item,index) in parames.userIdList" :key="index">
                  <el-col style="margin-bottom:10px" v-if="index==0" >
                    <span class="team-icon" style="background: #409efe" v-if="item.userName">{{item.userName.slice(0,1)}}</span>
                    <span class="team-name">{{item.userName}}</span>
                  </el-col>
                  <el-col style="margin-bottom:10px" v-if="index>0" >
                    <span class="team-icon" style="background: #409efe" v-if="item.userName">{{item.userName.slice(0,1)}}</span>
                    <span class="team-name">{{item.userName}}</span>
                    <i class="el-icon-delete team-del" @click="handleDeleteUser(index,item)"></i>
                  </el-col>
                </span>
              </el-row>
              <el-button type="text" style="margin-top:14px" @click="handleAddTeam" icon="el-icon-plus">添加新成员</el-button>
            </div>
          </el-col>
        </el-row>
        
        <div class="from-bottom-box">
          <el-button size="small" type="primary" :loading="loadingBtn" @click="handleSave">保存</el-button>
          <el-button size="small" @click="handleClose">取消</el-button>
        </div>
      </a-drawer>
      <caseDialog :caseData="caseData" @getThink="getThink"></caseDialog>
      <productDialog :productData="productData" @watchSlect="watchSlect"></productDialog>
      <teamDialog :teamData="teamData" @selectUser="selectUser"></teamDialog>

    </div>
</template>

<script>
import caseDialog from './caseDialog'
import productDialog from './productDialog'
export default {
    props: ['dialogData'],
    data() {
        return {
          loading: false,
          loadingBtn: false,
          activeNames: ['1','2'],
          parames: {
            id: '',
            contacts: '', //联系人
            contactType: '', //联系方式
            mobile: '', //联系手机号
            customerName: '', //客户名称
            customerId: '', //客户id
            opportunitySourceType: '', //商机来源类型
            opportunitySourceId: '', //商机来源
            urgencyLabel: '', //紧急程度
            importanceLabel: '',//重要程度
            thinkTankId: '', //推荐方案
            opportunityOverview: '', //商机概述
            relatedContractId: '', //关联合同
            // responsiblePerson: '', //当前负责人
            customLabelList: [], //自定义标签
            opportunityProductList: [], //产品列表
            userIdList: [], //团队成员
          },
          teamData: {
            show: false
          },
          caseData: {
            show: false
          },
          productData: { //产品
            slectData: [],
            show: false
          },
          teamData: {
            show: false
          },
          rules: {
            contacts: [{ required: true, message: '请输入联系人名称', trigger: ['change','blur' ]}],
            mobile: [{ required: true, message: '请输入联系方式', trigger: ['blur' ]}],
            customerName: [{ required: true, message: '请输入客户名称', trigger: ['change','blur' ]}],
            customerId: [{ validator: (rule, value, callback) => {
              if (value === '' && this.parames.customerName === '') {
                callback(new Error('请选择客户'));
              } else {
                callback();
              }
            }, trigger: ['change','blur' ] }],
            opportunitySourceId: [{ required: true, message: '请选择商机来源', trigger: ['blur']}],
          },
          contactType: [], //联系方式
          importData: [], //重要程度
          urgencyData: [], //紧急程度
          inputVisible: false,
          inputValue: '',
          groupListta: [], //产品组合
          kehuData: [],
          showKehu: true,
          selectType: [] //选中的产品组合
        };
    },
    methods: {
      handleBack () { //商机-ec机器人详情
        this.$emit('checkOpen')
        this.handleClose()
      },
      handleSelectCustomer () { //选择客户
        this.showKehu = !this.showKehu
        if (this.showKehu) {
          this.parames.customerName = ''
        } else {
          this.parames.customerId = ''
        }
      },
      handleClose () { //关闭弹窗
        this.dialogData.show = false
      },
      handleCancle () { //取消重新编辑
        this.dialogData.show = false
        this.$emit('checkOpen')
      },
      checkValue (value) { //来源获取信息
        this.parames.opportunitySourceType = value
      },
      getThink (value) { //获取方案信息
        this.parames.thinkTankId = value
        this.dialogData.thinkTankId = value
      },
      handleNewTeam () { //添加新成员
        this.teamData.show = true
      },
      selectUser (value) { //添加选择的成员
        if (this.dialogData.type == 'new') {
          let select = value //选中的数组
          let origan = this.parames.userIdList //本身存在的数组
          select.forEach(el=>{
            let i = 0
            origan.forEach((bl,index)=>{
              if (el.userId == bl.userId) {
                i = 1
              }
            })
            if (i !== 1) {
              this.parames.userIdList.push(el)
            }
          })
        } else {
          let select = value //选中的数组
          let userIdList = []
          let origan = this.parames.userIdList //本身存在的数组
          select.forEach(el=>{
            let i = 0
            origan.forEach((bl,index)=>{
              if (el.userId == bl.userId) {
                i = 1
              }
            })
            if (i !== 1) {
              userIdList.push(el.userId)
            }
          })
          this.$post(this.$api.postOpportunityTeamMemberAdd,{
            teamId: this.dialogData.id,
            userIdList: userIdList
          }).then(response => {
            if (response.data.succeed) {
              this.render()
            }
          })
        }
      },
      handleDeleteUser (index,item) { //删除组内人员
        if (item.teamMemberId) {
          this.$post(this.$api.postOpportunityTeamMemberDel,{
            teamMemberId: item.teamMemberId
          }).then(response => {
            if (response.data.succeed) {
              this.$message({ type:'success',message: '删除成功'})
              this.parames.userIdList.splice(index,1)
            }
          })
        } else {
          this.parames.userIdList.splice(index,1)
        }
      },
      watchSlect (data) { //监听返回的选中的数组
        let select = data //选中的数组
        let origan = this.parames.opportunityProductList //本身存在的数组
        this.parames.opportunityProductList = []
        select.forEach(el=>{
          this.parames.opportunityProductList.push({
            productId: el.productId,
            productName: el.productName,
            count: el.count?el.count:1,
            upperPriceLimit: el.upperPriceLimit,
            lowerPriceLimit: el.lowerPriceLimit,
            discount: el.discount?el.discount:0,
            giftCount: el.giftCount?el.giftCount:0,
            unitPrice: el.unitPrice?el.unitPrice:0,
            productServiceType: el.productServiceType?el.productServiceType:'',
          })
        })
        origan.forEach((el,index)=>{ //原来存在的数组
          this.parames.opportunityProductList.forEach(bl=>{ //现在新增的所有数组
            if(el.productId == bl.productId) { //有相同的值则把原来的值赋值过来
              if (el.id) {
                bl.id = el.id
              }
              bl.productId = el.productId
              bl.opportunityId = bl.opportunityId
              bl.discount = el.discount
              bl.count = el.count
              bl.giftCount = el.giftCount
              bl.unitPrice = el.unitPrice
            }
          })
        })
        // 选中的值和产品组合匹配勾选问题
        this.groupListta.forEach(el=>{
          let oData = []
          el.productList.forEach(bl=>{ //bl循环的数组组合
            this.parames.opportunityProductList.forEach(cl=>{ //cl当前点击的数组组合
              if (bl.id == cl.productId) {
                oData.push(bl)
              }
            })
            if ((oData.length == el.productList.length)) {
              el.isSelect = true
            }
          })
        })
      },
      handleCloseTag(tag) { //删除标签
        this.parames.customLabelList.splice(this.parames.customLabelList.indexOf(tag), 1);
      },
      showInput() { //改变标签状态自动聚焦
        this.inputVisible = true;
        this.$nextTick(_ => {
          this.$refs.saveTagInput.$refs.input.focus();
        });
      },
      handleDelproduct (index,row) { //删除当前行产品
        // if (row.id) { //接口删除
        //   this.$post(this.$api.postOpportunityProductDel,{
        //     opportunityProductId: row.id
        //   }).then(response => {
        //     this.parames.opportunityProductList.splice(index,1)
        //   })
        // } else { //新增时的删除
          
        // }
        this.parames.opportunityProductList.splice(index,1)
        this.groupListta.forEach(el=>{
          el.productList.forEach(bl=>{
            if (row.productId == bl.id) {
              el.isSelect = false
            }
          })
        })
      },
      handleAddTeam () { //添加团队成员
        this.teamData.show = true
      },
      handelAddProduct () { //添加产品
        this.productData.slectData = this.parames.opportunityProductList
        this.productData.show = true
      },
      handleInputConfirm() { //添加标签
        let inputValue = this.inputValue;
        if (inputValue) {
          this.parames.customLabelList.push(inputValue);
        }
        this.inputVisible = false;
        this.inputValue = '';
      },
      getSummaries(param) { //产品合计
        const { columns, data } = param;
        const sums = [];
        let values = []
        columns.forEach((column, index) => {
          if (index === 1) {
            sums[index] = '合计';
            return;
          }
          if (column.property == 'unitPrice') {
            values = data.map(item => Number(item.unitPrice * item.count-item.discount))
          }
          if (!values.every(value => isNaN(value)) && index == 7) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0);
            sums[index] += '.00';
          } else {
            sums[index] = '';
          }
        });
        return sums;
      },
      setData () {
        let userIdList = []
        this.parames.userIdList.forEach(el=>{
          userIdList.push(el.userId)
        })
        this.parames.userIdList = userIdList
        
        this.parames.opportunityProductList.forEach(el=>{
          if (el.productUnit) {
            el.productUnit = el.productUnit.name
          }
          if (el.productServiceType) {
            el.productServiceType = ''
          }
        }) 
      },
      handleSave () { //保存商机
        this.$refs['parames'].validate((valid) => {
          if (valid) {
            this.setData()
            // if (this.parames.opportunityProductList.length == 0) {
            //   this.$message.error('请录入产品数据');
            //   return false
            // }
            this.parames.opportunityProductList.forEach(el=>{
              if (el.discount<0 || (el.discount>(el.count*el.unitPrice))) {
                this.$message.error('合同产品优惠金额输入不正确');
                return false
              }
            })
            this.loadingBtn = true
            if (this.dialogData.type == 'edit') { //修改保存成功
              this.$post(this.$api.postOpportunityEdit,this.parames).then(response => {
                if (response.data.succeed) {
                  this.$message({ type:'success',message: '修改成功'})
                  this.handleClose()
                  this.$emit('checkOpen','1') //重新打开父级弹窗
                }
              })
            } else { //新增
              this.$post(this.$api.postOpportunityAdd,this.parames).then(response => {
                if (response.data.succeed) {
                  this.$message({ type:'success',message: '保存成功'})
                  this.$emit('checkRender')
                  this.handleClose()
                }
              })
            }
            setTimeout(() => {
              this.loadingBtn = false
            }, 300);
          }
        })
      },
      handleOpenCase () { //创建推荐方案
        this.caseData.type = 'new'
        this.caseData.show = true
      },
      handleViewCase () { //查看推荐方案
        this.caseData.type = 'edit'
        this.caseData.id = this.parames.thinkTankId
        this.caseData.show = true
      },
      render () { //获取详情信息
        this.loading = true
        this.$post(this.$api.postOpportunityFind,{
          opportunityId: this.dialogData.id
        }).then(response => {
          if (response.data.succeed) {
            this.loading = false

            let data = response.data.data
            this.parames.id = data.id
            this.parames.contacts = data.contacts //联系人
            this.parames.contactType = data.contactType.name //联系方式
            this.parames.mobile = data.mobile //联系手机号
            this.parames.customerName = data.customerName //客户名称
            this.parames.customerId = data.customerId
            if (data.customerId) {
              this.showKehu = true
            } else {
              this.showKehu = false
            }
            this.parames.opportunitySourceType = data.opportunitySourceType.name //商机来源类型
            this.parames.opportunitySourceId = data.opportunitySourceId //商机来源
            if (data.urgencyLabel) {
              this.parames.urgencyLabel = data.urgencyLabel.name //紧急程度
            }
            if (data.importanceLabel) {
              this.parames.importanceLabel = data.importanceLabel.name //重要程度
            }
            this.parames.userIdList = data.teamMemberList
            this.parames.thinkTankId = data.thinkTankId //推荐方案
            this.parames.opportunityOverview = data.opportunityOverview //商机概述
            // this.parames.relatedContractId = '' //关联合同
            // this.parames.responsiblePerson = data.responsiblePerson //当前负责人
            // this.parames.responsibleDepartment = '' //当前责任部门
            this.parames.customLabelList = data.customLabelList //自定义标签
            this.parames.opportunityProductList = data.opportunityProductList

            // 选中的值和产品组合匹配
            setTimeout(() => {
              this.groupListta.forEach(el=>{
                let oData = []
                el.productList.forEach(bl=>{ //bl循环的数组组合
                  data.opportunityProductList.forEach(cl=>{ //cl当前点击的数组组合
                    if (bl.id == cl.productId) {
                      oData.push(bl)
                    }
                  })
                  if ((oData.length == el.productList.length)) {
                    el.isSelect = true
                  }
                })
              })
            }, 200);
            
          }
        })
      },
      postProductGroupList () { //获取所有产品组合
        this.$post(this.$api.postProductGroupList).then(response => {
            if (response.data.succeed) {
              response.data.data.forEach(el=>{
                el.isSelect = false
              })
              this.groupListta = response.data.data
            }
        })
      },
      handleTags (item,index) { //点击产品组合-id保存到productId
        item.isSelect = !item.isSelect
        let origin = item.productList
        if (item.isSelect) { //添加
          let newArr = []
          origin.forEach(el => {
            newArr.push({
              productId: el.id,
              productName: el.productName,
              count: el.count?el.count:1,
              giftCount: el.giftCount?el.giftCount:0,
              unitPrice: el.unitPrice?el.unitPrice:0,
              discount: el.discount?el.count:0,
              upperPriceLimit: el.upperPriceLimit,
              lowerPriceLimit: el.lowerPriceLimit,
              productServiceType: el.productServiceType,
            })
          })
          // 数组去重重新添加到list里面
          var arr3 = this.$utils.unique2(newArr.concat(this.parames.opportunityProductList),'productId')
          this.watchSlect(arr3)
          // 选中时如果点击的产品组合的范围包含另外一个产品组合，那么另外一个也要选上
          this.groupListta.forEach(el=>{
            let oData = []
            el.productList.forEach(bl=>{ //bl循环的数组组合
              origin.forEach(cl=>{ //cl当前点击的数组组合
                if (bl.id == cl.id) {
                  oData.push(bl)
                }
              })
              if ((oData.length == el.productList.length) && el.id !== item.id) {
                el.isSelect = true
              }
            })
          })
        } else { //取消选中
          origin.forEach(bl => {
            for(let i=this.parames.opportunityProductList.length-1;i>=0;i--){
              if(this.parames.opportunityProductList[i].productId === bl.id){
                this.parames.opportunityProductList.splice(i,1);
              }
            }
          })
          // 取消选中时如果点击的产品组合的范围包含另外一个产品组合，那么另外一个也要选上
          this.groupListta.forEach(el=>{
            let oData = []
            el.productList.forEach(bl=>{ //bl循环的数组组合
              origin.forEach(cl=>{ //cl当前点击的数组组合
                if (bl.id == cl.id) {
                  oData.push(bl)
                }
              })
              if (oData.length>0) {
                el.isSelect = false
              }
            })
          })
        }
      },
      getKehu() { //获取客户下拉数据
        this.$post(this.$api.postCustomerCoreListForContract).then(response => {
          if (response.data.succeed) {
              this.kehuData = response.data.data
          }
        })
      },
      resetData () { //重置数据
        this.parames.contacts = '' //联系人
        this.parames.contactType = '' //联系方式
        this.parames.mobile = '' //联系手机号
        this.parames.customerName = '' //客户名称
        this.parames.opportunitySourceType = '' //商机来源类型
        this.parames.opportunitySourceId = '' //商机来源
        this.parames.urgencyLabel = '' //紧急程度
        this.parames.importanceLabel = ''//重要程度
        this.parames.thinkTankId = '' //推荐方案
        this.parames.opportunityOverview = '' //商机概述
        this.parames.relatedContractId = '' //关联合同
        // this.parames.responsiblePerson = '' //当前负责人
        this.parames.responsibleDepartment = '' //当前责任部门
        this.parames.customLabelList = [] //自定义标签
        this.parames.userIdList = [] //团队成员
        this.showKehu = true
        this.$refs.parames.resetFields()
        this.parames.opportunityProductList = [] //产品列表
      }
    },
    components: {
      caseDialog,
      productDialog
    },
    computed: {
      changeDialog () {
        return this.dialogData.show
      }
    }, 
    watch: {
      changeDialog: {
        handler (curVal, oldVal) {
          if (curVal) {
            this.$utils.getEnumberation('postContactType','contactType',this) //获取联系方式
            this.$utils.getEnumberation('postOpportunityImportanceLabel','importData',this) //重要程度
            this.$utils.getEnumberation('postOpportunityUrgencyLabel','urgencyData',this) //紧急程度
            this.postProductGroupList()
            this.getKehu()
            let userInfo = this.$utils.getLocalStorage('user')
            if (this.dialogData.type == 'new') {
              this.parames.userIdList.push({
                userName: userInfo.name,
                userId: userInfo.id
              })
            }
            if (this.dialogData.origin == 'ec') { //ec机器人转化
              this.parames.contactType = 'MOBILE'
              this.parames.contacts = this.dialogData.contacts
              this.parames.mobile = this.dialogData.contactNumber
            }
            if (this.dialogData.thinkTankId) {
              this.parames.thinkTankId = this.dialogData.thinkTankId
            }
            if (this.dialogData.type == 'edit') {
              this.render()
            }
          } else {
            this.resetData()
          }
        }
      }
    },
};
</script>

<style scoped>
.tab-cur {
 background: url() no-repeat 100% 100%;

}
</style>
